<!--- 
LICENSE INFORMATION:

Copyright 2007, Hem Talreja
 
Licensed under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance with the License. 

You may obtain a copy of the License at 

	http://www.apache.org/licenses/LICENSE-2.0 
	
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
CONDITIONS OF ANY KIND, either express or implied. See the License for the 
specific language governing permissions and limitations under the License.

VERSION INFORMATION:	(0.1)

 --->
<cfcomponent hint="designed to retreive details about the database using coldfusion version 8.0">
	
	<!--- 
		<cfdbinfo
    		datasource="#datasource#"
    		name="selTables"
    		type="dbnames|tables|columns|version|procedures|foreignkeys|index"
	    	dbname="database name"
	    	password="password"
	    	pattern="filter pattern"
	    	table="table name"
    		username="username" >
	 --->
	
	<cffunction name="getTables" access="public" returntype="query">
		<cfargument name="datasource" type="string" required="true" />
		<cfargument name="dbname" type="string" required="false" />
		<cfargument name="filterCriteria" type="string" required="false" default="" />
		
		<cfset var selTables = "" />
		
		<cfif isdefined("Arguments.dbname") AND Arguments.dbname is not "">
			<cfdbinfo datasource="#datasource#" dbname="#dbname#" name="selTables" type="tables" />
		<cfelse>
			<cfdbinfo datasource="#datasource#" name="selTables" type="tables" />
		</cfif>
	
		<cfreturn FilterRecords(selTables,filterCriteria) />
	</cffunction>
	
	
	<cffunction name="getColumns" access="public" returntype="query">
		<cfargument name="datasource" type="string" required="true" />
		<cfargument name="table" type="string" required="true" />
		<cfargument name="dbname" type="string" required="false" />
		<cfargument name="filterCriteria" type="string" required="false" default="" />
		
		
		<cfset var selColumns = "" />
		
		<cfif isdefined("Arguments.dbname") AND Arguments.dbname is not "">
			<cfdbinfo datasource="#datasource#" name="selColumns" type="columns" table="#table#" dbname="#dbname#" />
		<cfelse>
			<cfdbinfo datasource="#datasource#" name="selColumns" type="columns" table="#table#" />
		</cfif>
		
		<cfreturn FilterRecords(selColumns,filterCriteria) />
	</cffunction>
	
	
	<cffunction name="getIndexes" access="public" returntype="query">
		<cfargument name="datasource" type="string" required="true" />
		<cfargument name="table" type="string" required="true" />
		<cfargument name="dbname" type="string" required="false" />
		<cfargument name="filterCriteria" type="string" required="false" default="" />
		
		<cfset var selIndexes = "" />
	
		<cfif isdefined("Arguments.dbname") AND Arguments.dbname is not "">
			<cfdbinfo datasource="#datasource#" name="selIndexes" type="index" table="#table#" dbname="#dbname#" />
		<cfelse>
			<cfdbinfo datasource="#datasource#" name="selIndexes" type="index" table="#table#" />
		</cfif>
		
		<cfreturn FilterRecords(selIndexes,filterCriteria) />
	</cffunction>
	
	
	<cffunction name="getForeignKeys" access="public" returntype="query">
		<cfargument name="datasource" type="string" required="true" />
		<cfargument name="table" type="string" required="true" />
		<cfargument name="dbname" type="string" required="false" />
		<cfargument name="filterCriteria" type="string" required="false" default="" />
		
		<cfset var selForeignKeys = "" />
	
		<cfif isdefined("Arguments.dbname") AND Arguments.dbname is not "">
			<cfdbinfo datasource="#datasource#" name="selForeignKeys" type="ForeignKeys" table="#table#" dbname="#dbname#" />
		<cfelse>
			<cfdbinfo datasource="#datasource#" name="selForeignKeys" type="ForeignKeys" table="#table#" />
		</cfif>
		
		<cfreturn FilterRecords(selForeignKeys,filterCriteria) />
	</cffunction>


	
	<cffunction name="FilterRecords" access="public" returntype="query">
		<cfargument name="data" type="query" required="true" />
		<cfargument name="filterCriteria" type="string" required="true" />
		
		<cfset var selReturnData = Arguments.data />
		
		<cfif Trim( Arguments.filterCriteria ) IS NOT "">
			<cfquery dbtype="query" name="selReturnData">
				SELECT * FROM DATA
				WHERE #PreserveSingleQuotes(Arguments.filterCriteria)#
			</cfquery>
		</cfif>
		
		<cfreturn selReturnData />
	</cffunction>
		
</cfcomponent>